home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6284 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.0 KB

  1. Path: news.microsoft.com!news
  2. From: a-cnadc@microsoft.com (Dann Corbit)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Conversion between 80 and 64 bit doubles
  5. Date: 23 Feb 1996 18:49:10 GMT
  6. Organization: Microsoft Corporation
  7. Message-ID: <4gl276$1al@news.microsoft.com>
  8. References: <4gifto$aaa@news2.deltanet.com>
  9. NNTP-Posting-Host: 157.57.171.202
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.14
  12.  
  13. In article <4gifto$aaa@news2.deltanet.com>, fuz@deltanet.com says...
  14. >
  15. >
  16. >As part of a project I am working on, I have to convert between
  17. >an 80 bit double written on a PC to a 64 bit unix number.  On
  18. >most platforms I have seen, this would not be all that hard,
  19. >since the one time it has come up, the 64 bit platform (Mac PPC) had a 
  20. >conversion routine.  This time, it will not be as kind, as the client 
  21. >wants a more general answer.  While I might be able to find a conversion 
  22. >routine that will work on his AIX compiler, he has hinted darkly that he 
  23. >will be moving to other compilers as well, and could I please write a 
  24. >general converter?
  25. >
  26. >This is a fairly simple task in one sense - I know the numebrs in 
  27. >question will be in range of  64 bit double, and that they will not be 
  28. >NANs, so all I must do is convert the valid parts.
  29. >
  30. >Does anyone have a source for such a conversion routine, given that the 
  31. >platform in question does not have an 80 bit type?  The bit flipping for 
  32. >PC-Unix is not a problem - that works already.
  33. >
  34. >(BTW, a URL for the official specs for 64 and 80 bit numbers would be 
  35. >greatly appreciated.  I have tried to find IEEE 754, but I have not 
  36. >succeeded yet, which likely means that I am just searching for it in 
  37. >entirely the wrong way.)
  38. >
  39. >Scott
  40. >--
  41. >Scott Ellsworth          fuz@deltanet.com
  42. >"When a great many people are unable to find work, unemployment 
  43. >results" - Calvin Coolidge, (Stanley Walker, City Editor, p. 131 (1934))
  44. >"The barbarian is thwarted at the moat." - Scott Adams
  45. I once wrote a general purpose floating point conversion routine.
  46. Create a structure that contains the following for each number type:
  47. 1. The number of significant bits "n"
  48. 2. The order of significance of the bits, from most significant to least (array).
  49. 3. The number of bits for the exponent.
  50. 4. The bias of the exponent.
  51. 5. The position of the sign.
  52. Now, to convert from one type to another,
  53. 1. Transfer the bits from most significant down to least.
  54.    If there are too many bits, stop when the target is full.
  55.    (you may want to perform special rounding here  - banker's etc)
  56.    If there are not enough bits, fill in the rest with 0 bits.
  57. 2. Convert the source exponent into an integer
  58.    If the exponent is too large, trigger exception handling
  59.    ( you might return MAX_<FLOATTYPE> or INF )
  60.    If the exponent is too small, trigger exception handling
  61.    ( you might return MIN_<FLOATTYPE> or 0 with TLOSS )
  62. 3. convert integer to target exponent format
  63. 4. Transfer exponent.
  64. 5. Transfer the sign.
  65. -- 
  66. The opinions expressed in this message are my own personal views 
  67. and do not reflect the official views of Microsoft Corporation.
  68.  
  69.